﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoreRay
{
    public abstract class SceneView
    {
        public abstract string Name
        {
            get;
        }

        public SceneViewNode RootNode
        {
            get;
            protected set;
        }

        public virtual void OnSceneObjectAdded(SceneObject parentObject, SceneObject sceneObject)
        {

        }

        public virtual void OnSceneObjectDeleted(SceneObject sceneObject)
        {

        }

        public SceneViewNode FindSceneViewNode(SceneObject sceneObject)
        {
            return FindSceneViewNode(this.RootNode, sceneObject);
        }

        private SceneViewNode FindSceneViewNode(SceneViewNode parent, SceneObject sceneObject)
        {
            if (parent.SceneObject == sceneObject)
            {
                return parent;
            }

            else if(parent.ChildrenNodes.Count > 0)
            {
                SceneViewNode foundNode = null;

                foreach (var node in parent.ChildrenNodes)
                {
                    foundNode = FindSceneViewNode(node, sceneObject);

                    if (foundNode != null)
                    {
                        return foundNode;
                    }
                }
            }

            return null;
        }
    }
}
